a = input()
if len(a) == 4:
    v1 = a[0]
    v2 = a[1]
    v3=a[2]
    v4=a[3]
    f = [int(v1), int(v2), int(v3), int(v4), int(v1 + v2), int(v3 + v4), int(v1 + v2 + v3), int(v2 + v3 + v4), int(v1 + v2 + v3 + v4)]
    b = 0
    s = []
    for c in f:
        b = 0
        for d in range(2, c - 1):
            if c % d == 0:
                b = 1
        if b == 0:
            s.append(c)
if len(s) > 0:
    print(max(s))
else:
    print(0)
